<template>
  <div>
    <!-- 搜索区域 -->
    <div class="search-bar">
      <div style="display: flex; justify-content: flex-start;">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="搜索：">
            <el-select v-model="searchForm.condition" placeholder="请选择" style="width: 120px;">
              <el-option label="全部" value="all"></el-option>
              <el-option label="陪玩姓名" value="playmateName"></el-option>
              <el-option label="陪玩昵称" value="playmateNickname"></el-option>
              <el-option label="消费类型" value="spentTypeName"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-input v-model="searchForm.keyword" placeholder="请输入搜索内容" style="width: 160px;"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="handleSearch" style="height: 32px; padding: 0 12px; font-size: 12px;">搜索</el-button>
          </el-form-item>

          <el-form-item>
            <el-button @click="resetSearch" style="height: 32px; padding: 0 12px; font-size: 12px;">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!-- 陪玩流水列表 -->
    <el-table :data="playmateWaterList" height="510" border style="width: 100%">
      <el-table-column 
        :label="header" 
        v-for="header in tableHeader" :key="header" 
        :prop="getPropName(header)"
        width="145" show-overflow-tooltip>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @size-change="changePageSize"               
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[2, 3, 4, 5, 7, 9]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      tableHeader: ['ID', '陪玩姓名', '陪玩昵称', '订单ID', '消费类型', '消费金额', '账户余额','类型', '创建时间'],
      playmateWaterList: [],
      count: 0,
      params: {
        pageNum: 1,
        pageSize: 9,
      },
      searchForm: {
        condition: 'all',
        keyword: ''
      }
    }
  },
  methods:{
     // 根据表头获取对应的属性名
    getPropName(header){
      const mapping = {
        'ID': 'id',
        '陪玩姓名': 'playmateName',
        '陪玩昵称': 'playmateNickname',
        '订单ID': 'orderId',
        '消费类型': 'spentTypeName',
        '消费金额': 'waterSpentMoney',
        '账户余额': 'waterAccountMoney',
        '类型':'waterPType',
        '创建时间': 'createTime'
      }
      return mapping[header];
    },
    // 加载陪玩流水列表
    async loadPlaymateWaterList() {
      const searchParams = {
        pageNum: this.params.pageNum,
        pageSize: this.params.pageSize,
        tenantId: 1,
         // 添加条件搜索字段
        playmateName: this.searchForm.condition === 'playmateName' ? this.searchForm.keyword : null,
        playmateNickname: this.searchForm.condition === 'playmateNickname' ? this.searchForm.keyword : null,
        spentTypeName: this.searchForm.condition === 'spentTypeName' ? this.searchForm.keyword : null
      };
      const response = await this.financeApi.getPlaymateWaterList(searchParams);
      if (response.code == 200) {
        this.playmateWaterList = response.data.list;
        this.count = response.data.total;
      }else{
        this.$message.error("查询失败");
      }
    },
     // 搜索
    handleSearch() {
      this.loadPlaymateWaterList();
    },
     // 重置搜索条件
    resetSearch() {
      this.searchForm.condition = 'all';
      this.searchForm.keyword = '';
      this.loadPlaymateWaterList();
    },
      // 改变页大小
    changePageSize(val) {
      this.params.pageSize = val;
      this.params.pageNum = 1;
      this.loadPlaymateWaterList();
    },
     // 改变当前页
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.loadPlaymateWaterList();
    }
  },
  created(){
    this.loadPlaymateWaterList();
  }
}
</script>

<style  scoped>
.search-bar {
  padding: 5px 0; /* 减小上下内边距 */
}

.demo-form-inline {
  display: flex;
  align-items: center;
  gap: 8px; /* 减小组件之间的间距 */
}

.el-form-item {
  margin-top: 0; /* 移除默认的顶部外边距 */
  margin-bottom: 0; /* 移除默认的底部外边距 */
}

.el-select .el-input__inner {
  height: 30px; /* 进一步减小高度 */
  font-size: 12px;
}

.el-input .el-input__inner {
  height: 30px; /* 进一步减小高度 */
  font-size: 12px;
}

.el-button {
  height: 30px; /* 进一步减小高度 */
  padding: 0 10px; /* 减小内边距 */
  font-size: 12px;
}
</style>